package com.xps.and.yuntong.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xps.and.yuntong.Entity.Dizhi;
import com.xps.and.yuntong.R;

import java.util.List;

/**
 * Created by administrator on 2017-12-12.
 */

public class DingDanAdapter1 extends BaseAdapter {
    private Context context;
    private LayoutInflater layoutInflater;
    //        private List<Food> data;
    private List<Dizhi> data;
//    Dizhi1 dizhi22 = new Dizhi1();
//    private ArrayList<Dizhi1> dizhi2 = new ArrayList<>();

    public DingDanAdapter1(Context context, List data_item) {
        this.context = context;
        this.data = data_item;
        layoutInflater = layoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
//            return 4;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
//            return 1;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = null;
        final ViewHolder viewHolder;

        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.dingdan_item2, null);
            viewHolder = new ViewHolder();


            viewHolder.iv_yuandian = (ImageView) convertView.findViewById(R.id.iv_yuandian);
            viewHolder.iv_qidian_zhongdian = (ImageView) convertView.findViewById(R.id.iv_qidian_zhongdian);
            viewHolder.tv_dizhi = (TextView) convertView.findViewById(R.id.tv_dizhi);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//        viewHolder.tv_dizhi.setText(data.get(position).getList().get(position).getDizhi1s());
        Log.e("111", position + "" + data.size() + "aaa");
//        if (data.size() > 1) {
//            if (position == 0) {
//
//                viewHolder.iv_yuandian.setVisibility(View.GONE);
//                viewHolder.iv_qidian_zhongdian.setVisibility(View.VISIBLE);
//                viewHolder.iv_qidian_zhongdian.setImageResource(R.drawable.qidian1);
//            } else if (position == data.size() - 1) {
//
//                viewHolder.iv_yuandian.setVisibility(View.GONE);
//                viewHolder.iv_qidian_zhongdian.setVisibility(View.VISIBLE);
//                viewHolder.iv_qidian_zhongdian.setImageResource(R.drawable.zhongdian1);
//
//            } else {
//
//
//            }
//
//
//        }
        if (data.size() > 1) {
            if (position == 0) {

                viewHolder.iv_yuandian.setVisibility(View.GONE);
                viewHolder.iv_qidian_zhongdian.setVisibility(View.VISIBLE);
                viewHolder.iv_qidian_zhongdian.setImageResource(R.drawable.qidian1);
                viewHolder.tv_dizhi.setText(data.get(position).getList().get(0).getDizhi1s());
            } else if (position ==  1) {

                viewHolder.tv_dizhi.setText(data.get(position).getList().get(1).getDizhi1s());

            } else {

                viewHolder.iv_yuandian.setVisibility(View.GONE);
                viewHolder.iv_qidian_zhongdian.setVisibility(View.VISIBLE);
                viewHolder.iv_qidian_zhongdian.setImageResource(R.drawable.zhongdian1);
            }
        }
        return convertView;
    }

    public class ViewHolder {
        ImageView iv_yuandian;
        ImageView iv_qidian_zhongdian;
        TextView tv_dizhi;

    }


}